using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using Csla.Validation;

namespace fitnesstrack.library
{ 
	[Serializable()] 
	public class SubCategoryInfo : Csla.ReadOnlyBase<SubCategoryInfo>
	{
		#region Business Properties and Methods

		//declare members
		private int _id = 0;
		private int _categoryID = 0;
		private string _name = string.Empty;

		[System.ComponentModel.DataObjectField(true, true)]
		public int Id
		{
			get
			{
				CanReadProperty("Id", true);
				return _id;
			}
		}

		public int CategoryID
		{
			get
			{
				CanReadProperty("CategoryID", true);
				return _categoryID;
			}
		}

		public string Name
		{
			get
			{
				CanReadProperty("Name", true);
				return _name;
			}
		}
 
		protected override object GetIdValue()
		{
			return _id;
		}

		#endregion //Business Properties and Methods

		#region Authorization Rules
		protected override void AddAuthorizationRules()
		{
			//TODO: Define authorization rules in SubCategoryInfo
			//AuthorizationRules.AllowRead("Id", "SubCategoryInfoReadGroup");
			//AuthorizationRules.AllowRead("CategoryID", "SubCategoryInfoReadGroup");
			//AuthorizationRules.AllowRead("Name", "SubCategoryInfoReadGroup");

		}

		#endregion //Authorization Rules

		#region Factory Methods
		private static int _newId = -1;

		internal static SubCategoryInfo GetSubCategoryInfo(SafeDataReader dr)
		{
			return new SubCategoryInfo(dr);
		}

		private SubCategoryInfo(SafeDataReader dr)
		{
			Fetch(dr);
		}
		#endregion //Factory Methods

		#region Data Access

		#region Data Access - Fetch
		private void Fetch(SafeDataReader dr)
		{
			FetchObject(dr);

			//load child object(s)
			FetchChildren(dr);
		}

		private void FetchObject(SafeDataReader dr)
		{
			_id = dr.GetInt32("ID");
			_categoryID = dr.GetInt32("CategoryID");
			_name = dr.GetString("Name");
		}

		private void FetchChildren(SafeDataReader dr)
		{
		}
		#endregion //Data Access - Fetch
		#endregion //Data Access
	}
}
